//
//  SearchView.m
//  FitTime
//
//  Created by dllo on 16/4/9.
//  Copyright © 2016年 赵建平. All rights reserved.
//

#import "SearchView.h"


@interface SearchView ()<UITableViewDataSource, UITableViewDelegate>



@end

@implementation SearchView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createTableView];
 
    }
    return self;
}

- (void)createTableView {
    
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain];

    }
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    [self addSubview:self.tableView];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.searchArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    
    AMapTip *tip = self.searchArr[indexPath.row];
    
    cell.textLabel.text =tip.name;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AMapTip *mapTip = self.searchArr[indexPath.row];
    [self.delegate cellDidSeletedWithLocation:mapTip.location WithName:mapTip.name];
    
}

- (void)setSearchArr:(NSMutableArray *)searchArr {
    _searchArr = searchArr;
    [_tableView reloadData];
}


@end
